{% if category_link and category and gallery %}
  <a href="{% url gallery_category category.slug %}#/gallery/{{ gallery.slug }}/">
{% else %}
  {% if link and gallery %}
    <a href="{% url gallery_gallery gallery.slug %}" rel="gallery">
  {% endif %}
{% endif %}
    <img src="{{ STATIC_URL }}{{ item.image }}" alt="{{ item.alt_text }}" class="item-{{ width }} cover{% if active %} active{% endif %}">
    {% if caption %}
      <figcaption>{{ gallery.name }}</figcaption>
    {% endif %}
{% if link and gallery or category_link and category and gallery %}
  </a>
{% endif %}